<?php
/**
 * Data model
 *
 * @category  DataModel
 * @package   DataModel
 * @author    DataModel Generator v1.1
 * @version   Revision: 127 
 */

/**
 * Data model for table "phpdoc_folder"
 *
 * @category  DataModel
 * @package   DataModel
 * @author    DataModel Generator v1.1
 * @version   Revision: 127 
 */
class PhpdocFolder extends BasePhpdocFolder
{
    public function getLocation()
    {
        $all = self::getAll();
        $folders = array();
        foreach($all as &$item) {
            $folders[$item->id] = $item;
        }
        $res = self::getLoc($this->parent_id, $folders);
        $res[] = $this->name;
        return implode($res,'/') . '/';
    }

    protected static function getLoc($folderId, &$folders)
    {
        $folder = $folders[$folderId];
        $res = array($folder->name);
        if($folder->parent_id) {
            $res = array_merge(self::getLoc($folder->parent_id, $folders),$res);
        }
        return $res;
    }

    public static function getFolder($path)
    {
        $folder = new PhpdocFolder();
        $name = end(explode( '/', $path ));
        return $folder->getByParams(array('name' => $name));
    }
}
